﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpaceSquirrel.Automation
{
	public class BirdAutomation : SpriteAutomation
	{
		private int counter = 0;
		private string mode = "stalk";
		private bool bikeLevel;

		public BirdAutomation(Sprite sprite, bool onBikeLevel)
			: base(sprite)
		{
			sprite.isEnemy = true;
			this.bikeLevel = onBikeLevel;
		}

		public override void DoStuff(PlayScene scene)
		{
			this.counter++;
			Sprite p = scene.Player;
			Sprite sprite = this.sprite;
			int dy;

			if (this.mode == "stalk")
			{
				dy = p.y - this.sprite.y;

				if (Math.Abs(dy) < 6) this.mode = "right";
				else if (dy > 0) this.sprite.dy += 3;
				else { this.sprite.dy -= 3; }
			}
			else if (this.mode == "right")
			{
				if (sprite.x < p.x) sprite.dx = 6;
				else this.mode = "left";
			}
			else // # mode == 'left'
			{
				int spriteX = sprite.x;
				if (this.bikeLevel)
				{
					spriteX -= this.counter * PlayScene.BIKE_SPEED;
				}

				if (spriteX > 7)
				{
					sprite.dx = -6;
				}
				else
				{
					this.mode = "stalk";
				}
			}

			if (this.bikeLevel)
			{
				sprite.dx += PlayScene.BIKE_SPEED;
			}
		}
	}
}
